function openAddProjectPage() {
    $('#myModal').modal();
}

function openProjectMemberPage() {
    var arrSelections = $("#dataTable").bootstrapTable('getSelections');
    if (arrSelections.length <= 0) {
        Ewin.alert("必须选择一条数据操作");
        return;
    }
    if (arrSelections.length > 1) {
        Ewin.alert("只能选择一个项目维护成员");
        return;
    }
    var projectId = arrSelections[0].id;
    // window.location.href="/project/projectMemberPage?projectId="+projectId;
    href("/project/projectMemberPage?projectId=" + projectId);
}

function href(url) {
    var i = url.lastIndexOf("?");
    var str1 = url.substr(0, i);
    var params = url.substr(i + 1);
    document.write("<form action=" + str1 + " method=post  name=form1 style='display:none'>");
    if (params.indexOf("&") > 0) {
        var p = params.split('&');
        p.forEach(function (value) {
            var k = value.split("=");
            document.write("<input type=hidden  name='" + k[0] + "' value='" + k[1] + "' />");
        });
    } else {
        var k = params.split("=");
        document.write("<input type=hidden  name='" + k[0] + "' value='" + k[1] + "' />");
    }
    document.write("</form>");
    document.form1.submit();
}

function submitProject() {
    var url = "/project/addProject";
    var projectName = $("#projectName").val();
    $.ajax({
        url: url,
        method: "post",
        data: {
            projectName: projectName
        },
        success: function (responseMessage) {
            if (responseMessage.success) {
                $("#projectName").val();
                $('#myModal').modal("hide");
                $("#dataTable").bootstrapTable("Refresh");
            }
        }
    })
}

function param(params) {
    var obj = {
        pageSize: params.limit,
        pageNum: (params.offset / params.limit) + 1
    };
    return obj;
}

$(function () {
    var interfaceUrl = "/project/getProject";
    $("#dataTable").bootstrapTable({
        url: interfaceUrl,
        method: "get",
        pageNumber: 1,
        pageSize: 10,
        pageList: [10, 20, 30, 40, 50],
        pagination: true,
        sidePagination: "server",
        cache: false,
        queryParams: param,
        height: 500,
        toolbar: "#toolbar",//这里面需要用到jquery的选择器
        paginationPreText: "上一页",
        paginationNextText: "下一页",
        striped: true,
        showRefresh: true,
        clickToSelect: true,
        sortable: false,
        sortOrder: "asc",
        columns: [
            {
                checkbox: true
            },
            {
                "title": "项目id",
                "field": "id"
            },
            {
                "title": "项目名",
                "field": "projectName"
            }
        ]
    })
});